home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / timeline / edit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  13.7 KB  |  380 lines

  1. /*
  2.  * Copyright (c) 1990, 1991 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/collab/TimeLine/RCS/edit.c,v 1.1 92/01/03 17:30:34 drapeau Exp $ */
  25. /* $Log:    edit.c,v $
  26.  * Revision 1.1  92/01/03  17:30:34  drapeau
  27.  * Slight modification to ClearAllHandler(); changed a reference from
  28.  * "NULL" to "0" to reflect change in ANSI-C definition of NULL to
  29.  * (void*)0.
  30.  * 
  31.  * Revision 1.0  91/09/30  16:54:36  chua
  32.  * Update to version 1.0
  33.  * 
  34.  * The parameter to ClearAllNotes (line 314) is now tlFrame, instead of tlFrame->instHead.
  35.  * 
  36.  * Revision 0.67  91/09/25  13:47:20  chua
  37.  * Changed the instrument field, instInfo, to editInfo. 
  38.  * Changed InstrumentInfo to EditInfo.
  39.  * 
  40.  * Revision 0.66  91/09/23  17:09:48  chua
  41.  * In line 323, change selectedInstrument to noteInstrument, as the latter is
  42.  * now used to indicate which instrument has the currently selected note.
  43.  * 
  44.  * Revision 0.65  91/08/26  14:21:14  chua
  45.  * Deleted the actualApps variable from the tlFrame structure.
  46.  * 
  47.  * Revision 0.64  91/08/08  15:47:01  chua
  48.  * In ClearAll routine, change return NULL to return item.
  49.  * 
  50.  * Revision 0.63  91/08/05  16:53:03  chua
  51.  * Deleted the RepaintCanvas routine, as it is no longer necessary.  In places where it
  52.  * is called, just call the ScrollToFirstQuarter routine, which will do the necessary
  53.  * repaint as well.
  54.  * 
  55.  * Revision 0.62  91/07/26  17:23:50  chua
  56.  * In the ClearAllHandler, clear all the entries in the region list as well.
  57.  * 
  58.  * Revision 0.61  91/07/24  10:32:44  chua
  59.  * In the ClearAllHandler, clear all the pause markers as well.
  60.  * 
  61.  * Revision 0.60  91/07/09  16:56:46  chua
  62.  * Some reformatting changes only.
  63.  * 
  64.  * Revision 0.59  91/06/04  17:37:13  chua
  65.  * Added the copyright comments in the beginning of the file.
  66.  * 
  67.  * Revision 0.58  91/06/04  17:22:32  chua
  68.  * Added a new function, ShowClipboardHandler, which will show the current clipboard (only if
  69.  * the clipboard is not already showing).
  70.  * 
  71.  * In the CutHandler and CopyHandler, add code to update the clipboard window if it is
  72.  * showing.
  73.  * 
  74.  * Revision 0.57  91/06/04  10:42:20  chua
  75.  * Added a call to UpdateHeader whenever there is a change in the status of
  76.  * the current document (the change flag set to 1).
  77.  * 
  78.  * Revision 0.56  91/06/03  11:10:45  chua
  79.  * Make changes to accomodate multiple documents.  This involves identifying
  80.  * which is the current active window, that is, the one where the last mouse
  81.  * click was done.
  82.  * 
  83.  * Revision 0.55  91/05/30  12:07:42  chua
  84.  * Added an extra parameter in the call to InitNotesInfo.  The second parameter,
  85.  * deselect, indicates if the currently selected note is to be deselected.
  86.  * 
  87.  * Revision 0.54  91/05/29  18:29:59  chua
  88.  * In the ClearAllHandler, the old panel list found in the info popup window is destroyed and a 
  89.  * new note created.  This seems to eliminate the problems of the application crashing when we
  90.  * try to insert a note after doing a clear all notes function.
  91.  * 
  92.  * Revision 0.53  91/05/29  17:04:09  chua
  93.  * Added the ClearAllNotes function call in the ClearAllHandler and set instrument->infoNote to
  94.  * NULL.
  95.  * 
  96.  * Revision 0.52  91/05/29  14:30:14  chua
  97.  * In the ClearAllHandler routine, in lines 208-211, the ClearNoteInfo and UpdateNotesCount function
  98.  * calls are no longer necessary, due to the rewriting of the InitNotesInfo function.
  99.  * 
  100.  * Revision 0.51  91/05/28  12:09:37  chua
  101.  * *** empty log message ***
  102.  * 
  103.  * Revision 0.50  91/05/24  16:35:49  chua
  104.  * *** empty log message ***
  105.  * 
  106.  * Revision 0.49  91/05/23  17:38:43  chua
  107.  * *** empty log message ***
  108.  * 
  109.  * Revision 0.48  91/05/22  16:38:04  chua
  110.  * Removed the CheckIfNoteSelected function.  Instead, everytime the SelectNoteInfo procedure
  111.  * in notesInfo.c is called, similar code as that in the CheckIfNoteSelected function is
  112.  * performed.
  113.  * 
  114.  * The CheckIfNoteSelected function calls in the edit function handlers are also deleted.
  115.  * 
  116.  * Revision 0.47  91/05/22  13:55:48  chua
  117.  * 
  118.  * 
  119.  * Revision 0.46  91/05/22  11:36:43  chua
  120.  * Added a call to CheckIfNoteSelected in the PasteHandler, just before calling the
  121.  * PasteFromClipboard routine.
  122.  * This is because if a note is selected, we can replace it with whatever is contained in
  123.  * the clipboard (provided the contents consists of just that particular instrument which the
  124.  * selected note belongs to).
  125.  * 
  126.  * Revision 0.45  91/05/16  15:22:25  chua
  127.  * Removed the undo menu function for the time being.  UndoHandler is deleted.
  128.  * 
  129.  * Revision 0.44  91/05/16  14:35:16  chua
  130.  * A new function CheckIfNoteSelected is added.  The capability to apply the edit functions to a
  131.  * single selected note, instead of a whole selected region is added.
  132.  * The function first checks if an area is selected.  If so, it doesn't do anything, since the
  133.  * edit functions will be as before (to a whole selected region).
  134.  * If no area is selected and the selectedInstrument pointer is not NULL, a check is then made
  135.  * to see if there is a note selected in this instrument.  If so, the coordinates of a selected
  136.  * region (startX, endX, startY, endY) are set to simulate the note being selected in a region.
  137.  * The edit functions in the file select.c are then called and the operations will be very similar
  138.  * as for a whole selected region.
  139.  * 
  140.  * This new function is called in the Cut, Copy, Delete and Paste Handlers. 
  141.  * 
  142.  * Revision 0.43  1991/05/15  02:55:28  chua
  143.  * A parameter is added in the calls to DeleteNotesFromList found in the CutHandler and
  144.  * DeleteHandler.
  145.  * The value is 1 to indicate that refreshing of the canvas is necessary after the delete notes
  146.  * operation is done.
  147.  *
  148.  * Revision 0.42  1991/04/24  00:54:59  chua
  149.  * Added the function calls for the Cut, Copy, Paste and Delete Handlers.  The functions called
  150.  * are found in select.c
  151.  *
  152.  * They are:
  153.  *
  154.  * CopyToClipboard
  155.  * DeleteNotesFromList
  156.  * PasteFromClipboard
  157.  *
  158.  * Also, since the instrument info pop-up window is now created whenever an instrument is created,
  159.  * instead of only when the 'Show notes info' button is pressed, there is no need to check if
  160.  * the pointer to the pop-up window is NULL in the ClearAllHandler function, since the pop-up
  161.  * window will always be present.
  162.  *
  163.  * Revision 0.41  1991/04/08  20:49:54  chua
  164.  * Added code to update the info pop-up windows when the notes are cleared in the ClearAllHandler procedure.
  165.  * This will clear all the panel lists and set the notes count to zero for all the info pop-up windows that
  166.  * have been created.
  167.  *
  168.  * Revision 0.40  1991/04/01  01:43:27  chua
  169.  * This file contains the menu notify procedures for the edit menu button.  The different edit functions at this
  170.  * point are:
  171.  * Cut, Copy, Paste, Delete, Undo, ClearAll.
  172.  * At present, only the ClearAll function is implemented.  This function clears the TimeLine of all notes,
  173.  * essentially leaving the user a fresh canvas to start with.  The function will check if any unsaved changes
  174.  * exist and give the user the option of going on or cancelling the operation if there are unsaved changes.
  175.  * */
  176.  
  177. static char editrcsid[] = "$Header: /Source/Media/collab/TimeLine/RCS/edit.c,v 1.1 92/01/03 17:30:34 drapeau Exp $";
  178.  
  179. #include "main.h"
  180.  
  181. /*
  182.  * Menu handler for `edit_menu (Cut)'.
  183.  * This function cuts out the selected area and copies it to the clipboard.
  184.  * It will then update the clipboard display if the window is visible.
  185.  */
  186. Menu_item CutHandler(item, op)
  187.      Menu_item    item;
  188.      Menu_generate    op;
  189. {
  190.   TimeLineFramePtr tlFrame;
  191.   TimeLine_window_objects * ip = (TimeLine_window_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  192.  
  193.   tlFrame = TimeLineWindow[xv_get(ip->controls, PANEL_CLIENT_DATA)];
  194.   switch (op) 
  195.   {
  196.    case MENU_DISPLAY:
  197.     break;
  198.    case MENU_DISPLAY_DONE:
  199.     break;
  200.    case MENU_NOTIFY:
  201.     CopyToClipboard(tlFrame);
  202.     DeleteNotesFromList(1, tlFrame);
  203.     if (xv_get(TimeLineWindow[0]->TimeLine_window->window, XV_SHOW) == TRUE) /* Update clipboard only if it is showing */
  204.     {
  205.       SetCanvasHeight(TimeLineWindow[0]);
  206.       ScrollToFirstQuarter(TimeLineWindow[0], 0, 1);
  207.     }
  208.     break;
  209.    case MENU_NOTIFY_DONE:
  210.     break;
  211.   }
  212.   return item;
  213. }
  214.  
  215. /*
  216.  * Menu handler for `edit_menu (Copy)'.
  217.  */
  218. Menu_item CopyHandler(item, op)
  219.      Menu_item    item;
  220.      Menu_generate    op;
  221. {
  222.   TimeLineFramePtr tlFrame;
  223.   TimeLine_window_objects * ip = (TimeLine_window_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  224.  
  225.   tlFrame = TimeLineWindow[xv_get(ip->controls, PANEL_CLIENT_DATA)];
  226.   switch (op) 
  227.   {
  228.    case MENU_DISPLAY:
  229.     break;
  230.    case MENU_DISPLAY_DONE:
  231.     break;
  232.    case MENU_NOTIFY:
  233.     CopyToClipboard(tlFrame);
  234.     if (xv_get(TimeLineWindow[0]->TimeLine_window->window, XV_SHOW) == TRUE) /* Update clipboard only if it is showing */
  235.     {
  236.       SetCanvasHeight(TimeLineWindow[0]);
  237.       ScrollToFirstQuarter(TimeLineWindow[0], 0, 1);
  238.     }
  239.     break;
  240.    case MENU_NOTIFY_DONE:
  241.     break;
  242.   }
  243.   return item;
  244. }
  245.  
  246. /*
  247.  * Menu handler for `edit_menu (Paste)'.
  248.  */
  249. Menu_item PasteHandler(item, op)
  250.      Menu_item    item;
  251.      Menu_generate    op;
  252. {
  253.   TimeLineFramePtr tlFrame;
  254.   TimeLine_window_objects * ip = (TimeLine_window_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  255.  
  256.   tlFrame = TimeLineWindow[xv_get(ip->controls, PANEL_CLIENT_DATA)];
  257.   switch (op) 
  258.   {
  259.    case MENU_DISPLAY:
  260.     break;
  261.    case MENU_DISPLAY_DONE:
  262.     break;
  263.    case MENU_NOTIFY:
  264.     PasteFromClipboard(tlFrame);
  265.     break;
  266.    case MENU_NOTIFY_DONE:
  267.     break;
  268.   }
  269.   return item;
  270. }
  271.  
  272. /*
  273.  * Menu handler for `edit_menu (Delete)'.
  274.  */
  275. Menu_item DeleteHandler(item, op)
  276.      Menu_item    item;
  277.      Menu_generate    op;
  278. {
  279.   TimeLineFramePtr tlFrame;
  280.   TimeLine_window_objects * ip = (TimeLine_window_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  281.  
  282.   tlFrame = TimeLineWindow[xv_get(ip->controls, PANEL_CLIENT_DATA)];
  283.   switch (op) 
  284.   {
  285.    case MENU_DISPLAY:
  286.     break;
  287.    case MENU_DISPLAY_DONE:
  288.     break;
  289.    case MENU_NOTIFY:
  290.     DeleteNotesFromList(1, tlFrame);
  291.     break;
  292.    case MENU_NOTIFY_DONE:
  293.     break;
  294.   }
  295.   return item;
  296. }
  297.  
  298. /*
  299.  * Menu handler for `edit_menu (Clear All)'.
  300.  * This function will clear the TimeLine.  It first check if there are unsaved changes.  If not, it will then free all notes on all instruments and
  301.  * then call the ScrollToFirstQuarter routine to clear the canvas and redraw all the cables. It will also update the information displayed on the info
  302.  * pop-up windows.  The old panel list is destroyed (if not, segmentation faults occur at times (not sure why), and a new panel list is created.
  303.  */
  304. Menu_item ClearAllHandler(item, op)
  305.      Menu_item       item;
  306.      Menu_generate   op;
  307. {
  308.   Instrument *instrument;
  309.   TimeLineFramePtr tlFrame;
  310.   TimeLine_window_objects * ip = (TimeLine_window_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  311.  
  312.   tlFrame = TimeLineWindow[xv_get(ip->controls, PANEL_CLIENT_DATA)];
  313.   switch (op) 
  314.   {
  315.    case MENU_DISPLAY:
  316.     break;
  317.    case MENU_DISPLAY_DONE:
  318.     break;
  319.    case MENU_NOTIFY:
  320.     if (CheckChanges(ClearAll, tlFrame) == NOTICE_YES)        /* Check if unsaved changes exist in edit list */
  321.     {
  322.       return item;
  323.     }
  324.     ClearAllNotes(tlFrame);                    /* Clear the notes for all the instruments */
  325.     FreePause(tlFrame);
  326.     UpdatePauseList(tlFrame, 0);
  327.     ClearAllRegion(tlFrame->RegionPopup->ClearAllRegionButton, NULL); /* Clear all the region */
  328.     instrument = tlFrame->instHead;        
  329.     while (instrument != NULL) 
  330.     {
  331.       xv_destroy_safe (instrument->editInfo->NoteInfoList);        /* Destroy the old panel list and create a new one */
  332.       instrument->editInfo->NoteInfoList = 0;
  333.       instrument->editInfo = EditInfo_EditInfoWindow_objects_initialize (instrument->editInfo, 
  334.                                      tlFrame->TimeLine_window->window);
  335.       xv_set(instrument->editInfo->NoteInfoList,            /* Attach the instrument's relative position as the PANEL_CLIENT_DATA. */
  336.          PANEL_CLIENT_DATA, instrument->relativePosition,        /* Lets the program know which instrument the panel belongs to. */
  337.          NULL);
  338.       InitNotesInfo(instrument, 1, tlFrame);
  339.       instrument = instrument->next;
  340.     }
  341.     tlFrame->noteInstrument = NULL;
  342.     tlFrame->change = 1;
  343.     UpdateHeader(tlFrame, 1);
  344.     ScrollToFirstQuarter(tlFrame, 0, 1);
  345.     break;
  346.    case MENU_NOTIFY_DONE:
  347.     break;
  348.   }
  349.   return item;
  350. }
  351.  
  352. /*
  353.  * Menu handler for `EditMenu (Show Clipboard ...)'.
  354.  * This function checks to see if the clipboard is open.  If not, it will update it and make it visible.
  355.  * The updating is done simply by calling the ScrollToFirstQuarter routine, which will update the instrument and note displays.
  356.  */
  357. Menu_item ShowClipboardHandler(item, op)
  358.      Menu_item    item;
  359.      Menu_generate    op;
  360. {
  361.   switch (op) 
  362.   {
  363.    case MENU_DISPLAY:
  364.     break;
  365.    case MENU_DISPLAY_DONE:
  366.     break;
  367.    case MENU_NOTIFY:
  368.     if (xv_get(TimeLineWindow[0]->TimeLine_window->window, XV_SHOW) == FALSE) 
  369.     {
  370.       SetCanvasHeight(TimeLineWindow[0]);
  371.       ScrollToFirstQuarter(TimeLineWindow[0], 0, 1);
  372.       xv_set(TimeLineWindow[0]->TimeLine_window->window, XV_SHOW, TRUE, NULL);
  373.     }
  374.     break;
  375.    case MENU_NOTIFY_DONE:
  376.     break;
  377.   }
  378.   return item;
  379. }
  380.